package leetcode.ge100;

import java.util.Stack;

class MinStack {

	public static void main(String[] args) {
		MinStack m = new MinStack();
		m.push(-2);
		m.push(0);
		m.push(-3);
	}

	private Stack<Entry> stack;

	/** initialize your data structure here. */
	public MinStack() {
		stack = new Stack<Entry>();
	}

	public void push(int x) {
		if(stack.isEmpty()){
			stack.push(new Entry(x, x));
		}else{
			stack.push(new Entry(x, Math.min(x, stack.peek().min)));
		}
	}

	public void pop() {
		stack.pop();
	}

	public int top() {
		return stack.peek().val;
	}

	public int getMin() {
		return stack.peek().min;
	}

	class Entry {

		int val;
		int min;

		public Entry(int val, int min) {
			super();
			this.val = val;
			this.min = min;
		}

	}
}